package com.yukefms.rule.state;

import com.yukefms.rule.interfaces.BARule;
import com.yukefms.rule.interfaces.BAStageRule;

import java.util.HashMap;
import java.util.Map;

/**
 * @Description
 * @Author Ping
 * @Date 2021/6/29 16:43
 **/
public class RuleStateFlyWeight {
    public static final String ACTIVATED = "activated" ;
    public static final String IN_ACTIVATED = "inactivated" ;
    public static final String SUCCESS = "success" ;
    public static final String UN_MATCHED = "unmatched" ;
    public static final String FAILED = "failed" ;
    public static final String WRONG_PERFORMING = "wrong performing" ;
    public static final String PARTIAL_MATCHED = "partial matched" ;

    private static Map<String, BARuleState> State_MAP = new HashMap<>();

    public static void doInit(BAStageRule relatedRule) {
        State_MAP.put(ACTIVATED, new ActivatedState(relatedRule)) ;
        State_MAP.put(IN_ACTIVATED, new InActivatedState(relatedRule)) ;
        State_MAP.put(SUCCESS, new SuccessState(relatedRule)) ;
        State_MAP.put(UN_MATCHED, new UnMatchedState(relatedRule)) ;
        State_MAP.put(FAILED, new FailedState(relatedRule)) ;
        State_MAP.put(WRONG_PERFORMING, new WrongPerformingState(relatedRule)) ;
        State_MAP.put(PARTIAL_MATCHED, new PartialMatchedState(relatedRule)) ;

    }
    public static void setInActivatedStateForRule(BAStageRule relatedRule) {
        getState(IN_ACTIVATED).setRelatedRule(relatedRule);
    }

    public static BARuleState getState(String stateKey) {
        return State_MAP.get(stateKey) ;
    }


}
